<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        // axios拦截器
        
        //1.请求拦截器-控制所有的请求
        axios.interceptors.request.use(function(config){
            console.log(config.url)
            config.headers.mytoken = 'nihao';
            return config;
        },function(err){
            console.log(err)
        })

        axios.defaults.baseURL = 'http://localhost:3000/'
        axios.get('adata').then(res=>console.log(res.data))
        alert('注意观察network里的请求头信息中的mytoken')

        //2.响应拦截器-数据返回之前加工处理后再返回
        axios.interceptors.response.use(function(res){
            console.log(res)
            var data = res.data;
            return data;
        },function(err){
            console.log(err)
        })

        axios.get('adata').then((data)=>console.log(data))
    </script>
</body>
</html>